package com.cc.poc.jms;

import net.ser1.stomp.Client;
import android.os.AsyncTask;

public class JmsListenerTask extends AsyncTask<String, Void, String> {

	private static Client client;
	
	@Override
	protected String doInBackground(String... params) {
		
		try {
			Integer port = Integer.valueOf(params[1]);
			client = new Client(params[0], port, params[2], params[3]);
			client.subscribe(params[4], new StompMessageListener());
			System.out.println("Waiting for messages...");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	

	public void onCancel(String queue, boolean interrupt) {
		client.unsubscribe(queue);
		client.disconnect();
		System.out.println("Done.");
		super.cancel(interrupt);
	}

}
